<template>
  <div class="content">
    <ul class="msg" v-if="token">
      <li class="msg-list" v-for="(item,index) in msgList" :key="index">
        <p>
          <span class="title">{{item.name}}</span>
          <span class="time">{{item.currentTime|dTimer}}</span>
          <span class="lou">{{index+1}}楼</span>
        </p>
        <div class="msg-info" v-html="item.say"></div>
      </li>
    </ul>
    <p v-else class="is-login">
      登录后才可以参与评论呦!!
      <button>去登录</button>
    </p>
  </div>
</template>

<script>
// import {mapGetters} from "vuex"
import { mapState } from "vuex";
export default {
  data() {
    return {
      msgList: []
    };
  },
  methods: {
    getData() {
      this.$axios.get("/takemsg").then(res => {
        if (res.data.code == 400) {
          this.$notify({
            title: "提醒",
            message: "目前还没有评论呦!",
            offset: 300
          });
        } else {
          this.msgList = res.data;
        }
      });
    }
  },
  computed: {
    // ...mapGetters["userName"]
    ...mapState(["token"])
  },
  activated() {
    this.getData();
  }
};
</script>

<style lang="less" scoped>
.content {
  margin-top: 20px;
  background: white;
  height: 100%;
  .msg {
    box-sizing: border-box;
    background: white;
    padding: 40px;
    height: 100%;
    .msg-list {
      background: rgb(238, 238, 238);
      height: 150px;
      border-radius: 5px;
      margin-bottom: 10px;
      p {
        .title {
          display: inline-block;
          width: 50px;
          height: 50px;
          background: blue;
          border-radius: 50%;
          line-height: 50px;
          text-align: center;
          margin-right: 30px;
        }
        .time {
          color: #aaa;
          font-size: 13px;
        }
        .lou {
          float: right;
          margin: 20px 50px 0 0;
        }
      }
      .msg-info {
        box-sizing: border-box;
        width: 90%;
        background-color: white;
        margin: 20px 0 20px 58px;
        padding: 10px;
        min-height: 50px;
        border-radius: 5px;
        font-size: 15px;
        color: #515250;
      }
    }
  }
  button {
    display: inline-block;
    height: 38px;
    padding: 0 18px;
    background-color: #009688;
    color: #fff;
    white-space: nowrap;
    text-align: center;
    font-size: 14px;
    border: none;
    border-radius: 2px;
    margin: 30px 0;
    cursor: pointer;
    transition: 0.5s;
  }
  .is-login {
    text-align: center;
    margin: 50px 0 30px;
    line-height: 90px;
  }
}
</style>